home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 6 / The Arsenal Files 6 (Arsenal Computer).ISO / prg_casm / jlvesa11.zip / JLVESA02.ASM < prev    next >
Assembly Source File  |  1996-01-03  |  7KB  |  265 lines

  1. ; This routine is part of VESA SVGA -library
  2. ;
  3. ; Copyright 1994 Johannes Lehtinen
  4. ; All rights reserved
  5.  
  6. model large,c
  7. p386
  8.  
  9. include "jlvesads.asm"
  10.  
  11. segment jlvesa02_TEXT USE16 'CODE'
  12. assume cs:jlvesa02_TEXT
  13.  
  14. ; Information for default VESA modes, starting from 100H
  15.  
  16.    ; List of default modes that can be used
  17.       def_modes   dw 100H,101H,103H,105H,107H
  18.    ; Width of modes listed before
  19.       def_width   dw 640,640,800,1024,1280
  20.    ; Height of modes listed before
  21.       def_height  dw 400,480,600,768,1024
  22.  
  23. ; Space for VESA video/mode information
  24.  
  25.       work_space  db    256 dup(?)
  26.  
  27. ; JLFlag JVSVGA_SetMode(JVUWord mode)
  28. ;
  29. ; Sets given VESA video mode. Mode should be 256 color mode. Function returns
  30. ; 0 if succesfull and 1 if not.
  31.  
  32. proc JVSVGA_SetMode far
  33.    public JVSVGA_SetMode
  34.  
  35.    push  bp
  36.    mov   bp,sp
  37.    push  ds
  38.    push  di
  39.    push  es
  40.  
  41.    mov   ax,JLVesa_Data
  42.    mov   ds,ax
  43.  
  44.    ; First check version number by loading VESA info
  45.  
  46.    mov   ax,cs
  47.    mov   es,ax                ; ES:DI = VESA info
  48.    mov   di,offset work_space
  49.    mov   ax,4f00H             ; Get VESA info
  50.    int   10H                  ; Call VESA BIOS
  51.    cmp   ax,4fH               ; Check if succesfull
  52.    jne   error1               ; Error, return
  53.  
  54.    ; Calculate amount of memory
  55.  
  56.    xor   eax,eax
  57.    mov   ax,[es:di+18]
  58.    shl   eax,16
  59.    mov   [ds:Size],eax
  60.  
  61.    ; Check version number
  62.  
  63.    cmp   [byte ptr es:di+5],1 ; Check if major > 1
  64.    ja    short success2
  65.    jb    error1               ; Check if major < 1
  66.    cmp   [byte ptr es:di+4],1 ; Check if minor >= 1
  67.    jb    error1
  68.  
  69.    ; Get mode information
  70.  
  71. success2:
  72.    mov   ax,4f01H             ; Get mode info
  73.    mov   cx,[ss:bp+6]         ; CX = mode
  74.    int   10H                  ; Call VESA BIOS
  75.    cmp   ax,4fH               ; Check if succesfull
  76.    jne   error1               ; Error, return
  77.  
  78.    ; Check if mode supported
  79.  
  80.    test  [byte ptr es:di],1   ; Test if supported
  81.    jz    error1               ; Not supported
  82.  
  83.    ; Check through nonoptional info
  84.  
  85.    test  [byte ptr es:di],8   ; Check that mode is color mode
  86.    jz    error1
  87.    test  [byte ptr es:di],16  ; Check that mode is graphics mode
  88.    jz    error1
  89.    cmp   [word ptr es:di+6],64   ; Check that window size is equal to or below 64K
  90.    ja    error1
  91.  
  92.    ; Check that there is window for read
  93.  
  94.    mov   al,[es:di+2]         ; Check window A for possible read window
  95.    and   al,3
  96.    cmp   al,3
  97.    jne   short read_check_b
  98.    mov   ax,[es:di+8]         ; Get information for win A
  99.    mov   [ds:RWSeg],ax
  100.    mov   [ds:RWin],0
  101.    jmp   short check_write
  102.  
  103. read_check_b:
  104.    mov   al,[es:di+3]         ; Check window B for possible read window
  105.    and   al,3
  106.    cmp   al,3
  107.    jne   error1               ; Read window not found
  108.    mov   ax,[es:di+10]        ; Get information for win B
  109.    mov   [ds:RWSeg],ax
  110.    mov   [ds:RWin],1
  111.  
  112.    ; Check that there is window for write
  113.  
  114. check_write:
  115.    mov   al,[es:di+2]         ; Check window A for possible write window
  116.    and   al,5
  117.    cmp   al,5
  118.    jne   short write_check_b
  119.    mov   ax,[es:di+8]         ; Get information for win A
  120.    mov   [ds:WWSeg],ax
  121.    mov   [ds:WWin],0
  122.    jmp   short test_optional
  123.  
  124. write_check_b:
  125.    mov   al,[es:di+3]         ; Check window B for possible write window
  126.    and   al,5
  127.    cmp   al,5
  128.    jne   error1               ; Write window not found
  129.    mov   ax,[es:di+10]        ; Get information for win B
  130.    mov   [ds:WWSeg],ax
  131.    mov   [ds:WWin],1
  132.  
  133.    ; Test if there is optional info available
  134.  
  135. test_optional:
  136.    test  [byte ptr es:di],2   ; Test if there is optional info available
  137.    jz    check_def            ; No optional info, check from table if usable
  138.  
  139.    ; Check trough optional info
  140.  
  141.    cmp   [byte ptr es:di+19H],8  ; Check that mode has 256 colors
  142.    jne   error1
  143.    cmp   [byte ptr es:di+1bH],4  ; Check that memory model is packed pixels
  144.    jne   error1
  145.  
  146.    ; Read optional info
  147.  
  148.    mov   ax,[es:di+12H]       ; Read width
  149.    mov   [ds:Width],ax
  150.    mov   ax,[es:di+14H]       ; Read height
  151.    mov   [ds:Height],ax
  152.    mov   ax,[es:di+1dH]       ; Read number of pages
  153.    inc   ax
  154.    mov   [ds:Pages],al
  155.  
  156.    ; Read nonoptional info
  157.  
  158. readinfo:
  159.    mov   ax,[es:di+10H]       ; Read logical width
  160.    mov   [ds:LWidth],ax
  161.    xor   eax,eax              ; Read window size
  162.    mov   ax,[es:di+6]
  163.    cmp   ax,64                ; Check that window size <= 64k
  164.    jbe   short size_ok
  165.    mov   ax,64
  166. size_ok:
  167.    shl   eax,10               ; Convert size from kilobytes to bytes
  168.    mov   [ds:WSize],eax
  169.    xor   eax,eax              ; Read window granularity
  170.    mov   ax,[es:di+4]
  171.    cmp   ax,64                ; Check that granularity <= 64k
  172.    ja    error1
  173.    shl   eax,10               ; Convert size from kilobytes to bytes
  174.    mov   [ds:Granularity],eax
  175.    mov   eax,[es:di+0cH]      ; Read address of window positioning function
  176.    mov   [ds:PosFunc],eax
  177.    mov   [ds:RAStart],0       ; Reset window to the start of video memory
  178.    mov   [ds:WAStart],0
  179.    mov   [ds:AStart],0
  180.    mov   [ds:VStart],0
  181.  
  182.    ; Select mode
  183.  
  184.    mov   ax,4f02H             ; Set mode
  185.    mov   bx,[ss:bp+6]
  186.    int   10H
  187.    cmp   ax,4fH
  188.    jne   short error1
  189.  
  190.    ; Calculate size of video page
  191.  
  192.    xor   eax,eax
  193.    xor   ebx,ebx
  194.    mov   ax,[ds:LWidth]       ; Multiply logical width with height
  195.    mov   bx,[ds:Height]
  196.    mul   ebx
  197.    mov   [ds:PSize],eax
  198.  
  199.    ; Set display start
  200.  
  201.    mov   ax,4f05H
  202.    xor   bx,bx
  203.    xor   cx,cx
  204.    xor   dx,dx
  205.    int   10H
  206.  
  207.    ; Position window to the start of video memory
  208.  
  209.    xor   bh,bh                ; Position read window
  210.    mov   bl,[ds:RWin]
  211.    xor   dx,dx
  212.    call  [ds:PosFunc]
  213.  
  214.    xor   bh,bh                ; Position write window
  215.    mov   bl,[ds:WWin]
  216.    xor   dx,dx
  217.    call  [ds:PosFunc]
  218.  
  219.    ; Return succesfully
  220.  
  221.    pop   es
  222.    pop   di
  223.    pop   ds
  224.    pop   bp
  225.    mov   al,0
  226.    retf
  227.  
  228.    ; This routine is called when something goes wrong
  229.  
  230. error1:
  231.    pop   es
  232.    pop   di
  233.    pop   ds
  234.    pop   bp
  235.    mov   al,1
  236.    retf
  237.  
  238.    ; This routine is called if no optional info is available
  239.  
  240. check_def:
  241.    xor   di,di                ; DI = offset of current mode
  242.    mov   ax,[ss:bp+6]         ; AX = mode
  243.  
  244. check_loop:
  245.    cmp   [cs:def_modes+di],ax ; Check if correct mode found on list
  246.    je    short check_found
  247.    add   di,2                 ; Check next mode
  248.    cmp   di,10                ; Check if modes left
  249.    jb    check_loop
  250.    jmp   short error1         ; Mode was not supported
  251.  
  252. check_found:                  ; Mode was found, get information from table
  253.    mov   ax,[cs:def_width+di] ; Read width
  254.    mov   [ds:Width],ax
  255.    mov   ax,[cs:def_height+di]   ; Read height
  256.    mov   [ds:Height],ax
  257.    mov   [ds:Pages],1
  258.    jmp   readinfo
  259.  
  260. endp JVSVGA_SetMode
  261.  
  262. ends
  263.  
  264. end
  265.